import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;


public class Comp {
	public static int arraySize ;
	private double[][] temps ;//= new double[arraySize][2];
	private double[] diffs;// = new double[arraySize]; 
	public Comp() {
		temps= new double[arraySize][2];
		diffs= new double[arraySize];
	}
	/**
	 * @param args
	 */
	
	public void beolvas(File mini, File telos) {
		String[] ss= new String[6];
		try{
			BufferedReader bMiniRead = new BufferedReader(new FileReader(mini));
			BufferedReader bTelosRead = new BufferedReader(new FileReader(telos));
			try{
			    int cnt = 0;
				String nextLine = null;
				while((nextLine=bMiniRead.readLine()) != null) {
					//StringTokenizer sTknr = new StringTokenizer(nextLine);
				    ss = nextLine.split(" ");
				    temps[cnt][0] = Double.parseDouble(ss[1]);
				    cnt++;
				}
				
				nextLine = null;
				cnt = 0;
				while((nextLine=bTelosRead.readLine())!= null) {
					ss = nextLine.split(" ");
					temps[cnt][1] = Double.parseDouble(ss[1]);
					cnt++;
				}
			}finally{
				bMiniRead.close();
				bTelosRead.close();
			}
		}catch (IOException e) {			
		}
			
	}
	
	private void doCompare() {
		for(int i=0; i< arraySize; i++) {
			diffs[i] = temps[i][1] - temps[i][0];
		}
	}
	
	private String doFormat(double inFloat) {
		String oS = String.valueOf(inFloat);
		String retString = oS.replace('.', ',');
		return retString;
	}
	
	private void printOut(File outFile) {
		PrintWriter pWriter = null;
		try{
			pWriter = new PrintWriter(outFile);
			
			pWriter.print("Ucmini;TelosB;Difference;\n");
			
			for(int pos=0; pos< arraySize; pos++)
			{
				pWriter.print(doFormat(temps[pos][0]));pWriter.print(';');
				pWriter.print(doFormat(temps[pos][1]));pWriter.print(';');
				pWriter.print(doFormat(diffs[pos]));pWriter.print(';');
				
				pWriter.print('\n');
			}
		}
		catch(FileNotFoundException fe) {
			
		}
		finally{
			pWriter.flush();
			pWriter.close();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Date date = new Date();
		if(args.length != 2)
		{
			System.out.println("Usage: java Comp ucmini_temp.txt telos_temp.txt");
			System.exit(0);
		}
		Comp.arraySize=1200;
		/*double pi= 3.14;
		String os = String.valueOf(pi);
		String op = os.replace('.', ',');
		System.out.print(op);*/
		Comp iComp = new Comp();
		iComp.beolvas(new File(args[0]), new File(args[1]));
		iComp.doCompare();
		iComp.printOut(new File("diff"+ String.valueOf( date.getTime()) +".csv"));
		/*try {
		PrintWriter pw = new PrintWriter("diff.csv");
		for (int ct=0; ct<10; ct++) {
			pw.print(3.14159);
			pw.print(';');
			pw.print(3.56);
			pw.print(';');pw.print('\n');
		}
		pw.flush();
		pw.close();
		}catch (FileNotFoundException fe){}
		*/
	}

}
